//
//  ClientsViewController.m
//  移动营销
//
//  Created by Hanen 3G 01 on 16/2/23.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//

#import "ClientsViewController.h"
#import "MyClientCell.h"
#import "DetailClientViewController.h"
#import "NewClientViewController.h"
#import "ClientModel.h"
#import "MyTabBarController.h"
#import "SelectViewController.h"
#import "SelectPersonViewController.h"
#import "OtherClientCell.h"
#import "OtherClientVC.h"

#define STARTX [UIView getWidth:10]

#import "TopSegmentView.h"
#import "MJRefresh.h"

@interface ClientsViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UISearchBarDelegate,SelectStaffViewDelegate,MyClientCellDelegate,SegViewDelegate>
{
    UIView          *view;
    UIView          *otherView;
    
    BOOL            isMyClient;
    NSArray         *_titleArray;
    UISearchBar     *_searchBar;
    UISearchBar     *_otherSearchBar;
    
    NSMutableArray  *_myDataArr;
    NSMutableArray  *_otherDataArr;
    
    UILabel         *_myBasicLabel;
    UILabel         *_otherBasicLabel;
    
    TopSegmentView * topSegmentView;
    
    UIView   *taxisView;//我的客户
    UIView   *paixuView;//下属客户
    UIButton  *_SortButton;
    UIButton *_paixuButton;
    //我的客户
    int   _lastTag;//记录上一个按钮
    int   _lastOtherTag;//记录图片
    //下属客户
    int   _lastImageTag;//记录上一个按钮
    int   _lastOtherImgTag;//记录上一个图片
    
    NSMutableArray  *_staffArray;
    BOOL   isDismiss;
    
    int pageNum;//我的客户
    int otherPageNum;//下属客户
    
}
@property(nonatomic,assign)BOOL  isManager;
@property(nonatomic,assign)BOOL  isJumpDetail;//为NO，刷新列表

@property(nonatomic,strong)TopSegmentView    *topBtnView;

//我的客户
@property(nonatomic,strong)UITableView     *myClientTableView;
@property(nonatomic,strong)UIView          *myClientView;

//下属客户
@property(nonatomic,strong)UITableView     *otherClientTableView;
@property(nonatomic,strong)UIView          *otherClientView;

@property(nonatomic,strong)NSMutableArray        *levelArr,*fromArr,*statusArr;//等级、来源、状态

@end

@implementation ClientsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = graySectionColor;
    self.navigationItem.hidesBackButton =YES;
    isMyClient = YES;
    
    _myDataArr = [NSMutableArray array];
    _otherDataArr = [NSMutableArray array];
    
    _staffArray = [NSMutableArray array];
    
    _levelArr = [NSMutableArray array];
    _fromArr = [NSMutableArray array];
    _statusArr = [NSMutableArray array];
    
    _titleArray = @[@"按拜访时间排序",@"按创建时间排序",@"按名称排序",@"按级别排序"];
    NSString *type = [[[NSUserDefaults standardUserDefaults]objectForKey:@"type"] stringValue];
    if ([type isEqualToString:@"2"]) {
        _topBtnView = [[TopSegmentView alloc] initWithFrame:CGRectMake(0, 0, 170.0f, 30)];
        _topBtnView.delegate = self;
        _topBtnView.rightTitle = @"我的客户";
        _topBtnView.leftTitle = @"下属客户";
        _topBtnView.indicatorViewColor = [UIColor whiteColor];
        _topBtnView.firstIndex = 1;
        self.navigationItem.titleView = _topBtnView;
        
        if (isMyClient == YES) {
            pageNum = 1;
            [self getTestData:1 WithSearch:nil withShow:YES];
            
        }else{
            int mydata;
            mydata = 1;
            otherPageNum = 1;
            [self initOtherData:mydata WithSearch:nil WithStaffArray:nil withShow:YES];
        }
    }else{
        self.navigationItem.titleView = [ViewTool getNavigitionTitleLabel:@"我的客户"];
        pageNum = 1;
        [self getTestData:1 WithSearch:nil withShow:YES];
    }
    
    
    
    _SortButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
    [_SortButton setBackgroundImage:[UIImage imageNamed:@"HY_nav_icon_sort.png"] forState:UIControlStateNormal];
    [_SortButton addTarget:self action:@selector(clickToSort) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_SortButton];
    _SortButton.selected = NO;
    //    _sortBarItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_sort.png" WithAction:@selector(clickToSort)];
    self.navigationItem.leftBarButtonItem = item;
    
    self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_screen" WithAction:@selector(clickToselectClient:)];self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_add" WithAction:@selector(clickToNewClient:)];
    
    
    [self initViews];
    
    [self addSortView];
    [self addViews];
    
    
    //获取数据字典
    [self getDictWith:1];//等级
    [self getDictWith:2];//状态
    [self getDictWith:3];//来源
    
}
#pragma mark
#pragma mark------数据字典
- (void)getDictWith:(int)number{
    
    NSNumber *num =[NSNumber numberWithInt:number];
    NSDictionary * dic =@{@"token":TOKEN,@"uid":@(UID),@"type":num };
    [DataTool postWithUrl:GET_DICTIONARY_URL parameters:dic success:^(id data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableArray *mutArray = [(NSDictionary *)jsonDic objectForKey:@"list"];
        //        NSLog(@"%@opopopopooopooppo",jsonDic);
        if (number == 1) {
            for (int i=0; i<mutArray.count; i++) {
                NSDictionary *dicc = mutArray[i];
                [_levelArr addObject:dicc[@"level"]];
            }
        }else if (number == 2){
            for (int i=0; i<mutArray.count; i++) {
                NSString *level = [mutArray[i] objectForKey:@"level"];
                [_statusArr addObject:level];
            }
        }else if (number == 3){
            for (int i=0; i<mutArray.count; i++) {
                NSString *level1 = [mutArray[i] objectForKey:@"level"];
                [_fromArr addObject:level1];
            }
        }
//            NSLog(@"%@%@%@",_levelArr,_statusArr,_fromArr);
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

- (void)initViews{
    
    view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, 44)];
    view.backgroundColor  = UIColorFromRGB(0xe8ecef);
    [self.view addSubview:view];
    
    UIView * lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0, view.height - 1, KSCreenW, 1)];
    lineView1.backgroundColor = grayLineColor;
    [view addSubview:lineView1];
    
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake([UIView getWidth:8], 0, KSCreenW - 2 * [UIView getWidth:8] , view.height - 1)];
    [_searchBar setBackgroundImage:[ViewTool getImageFromColor:UIColorFromRGB(0xe8ecef) WithRect:_searchBar.frame]];
    _searchBar.placeholder =@"搜索";
    _searchBar.delegate   = self;
    [view addSubview:_searchBar];
    
    
    otherView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, 44)];
    otherView.backgroundColor  = UIColorFromRGB(0xe8ecef);
    otherView.hidden = YES;
    [self.view addSubview:otherView];
    
    UIView * lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, otherView.height - 1, KSCreenW, 1)];
    lineView2.backgroundColor = grayLineColor;
    [otherView addSubview:lineView2];
    
    _otherSearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake([UIView getWidth:8], 0, KSCreenW - 2 * [UIView getWidth:8] , otherView.height - 1)];
    [_otherSearchBar setBackgroundImage:[ViewTool getImageFromColor:UIColorFromRGB(0xe8ecef) WithRect:_otherSearchBar.frame]];
    _otherSearchBar.placeholder =@"搜索";
    _otherSearchBar.delegate   = self;
    [otherView addSubview:_otherSearchBar];
    
    [self initMyClientView];
    [self initOtherClientView];
    
}

#pragma mark -------- 创建排序界面
#pragma mark------我的客户的下拉
- (void)addSortView
{
    taxisView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, [UIView getWidth:150.0f], [UIView getHeight:150.0f])];
    taxisView.backgroundColor = [UIColor clearColor];
    taxisView.hidden = YES;
    [self.view addSubview:taxisView];
    
    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, taxisView.width, taxisView.height)];
    bgImage.image = [UIImage imageNamed:@"HY_popup_bg"];
    bgImage.userInteractionEnabled = YES;
    
    [taxisView addSubview:bgImage];
    
    [self createTaxisView];
    
}

- (void)createTaxisView{
    
    CGFloat btnH = (taxisView.height - [UIView getHeight:10] - (_titleArray.count -1) * 1) / _titleArray.count;
    CGFloat btnW = taxisView.width - 20 - 20;
    for (int i = 0; i<_titleArray.count; i++) {
        UIButton  *btn = [[UIButton alloc] initWithFrame:CGRectMake(15, [UIView getHeight:10] + (btnH) * i, btnW, btnH)];
        [btn setTitle:_titleArray[i] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0f];
        btn.backgroundColor = [UIColor clearColor];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        [btn addTarget:self action:@selector(clickSort:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 302010+ i;
        
        [taxisView addSubview:btn];
        if (i != _titleArray.count - 1) {
            UIView *line = [ViewTool getLineViewWith:CGRectMake(0, btn.maxY, taxisView.width, 1) withBackgroudColor:[UIColor whiteColor]];
            [taxisView addSubview:line];
        }
        
        UIImageView  *imagev = [[UIImageView alloc] initWithFrame:CGRectMake(taxisView.width - 35, btn.y+ 12, 20, 20)];
        imagev.tag = 102030 + i;
        [taxisView addSubview:imagev];
    }
    
    _lastTag = 302010;
    //    UIButton *btn = (UIButton *)[taxisView viewWithTag:_lastTag];
    _lastImageTag = 102030;
    UIImageView  *image = (UIImageView *)[taxisView viewWithTag:_lastImageTag];
    image.image = [UIImage imageNamed:@"HY_popup_icon_selected"];
    
    
}
//点击 出现排序
- (void)clickToSort{
    NSLog(@"myclientview");
    if(_SortButton.selected == NO){
        taxisView.hidden = NO;
    }else{
        taxisView.hidden = YES;
    }
    _SortButton.selected = !_SortButton.selected;
}
//我的
- (void)clickSort:(UIButton *)btn
{
    NSLog(@"%@",btn.currentTitle);
    
    UIImageView *imageV = [taxisView viewWithTag:_lastImageTag];
    imageV.image = nil;
    
    UIImageView *clickImageV = [taxisView viewWithTag:102030 + (btn.tag - 302010)];
    clickImageV.image = [UIImage imageNamed:@"HY_popup_icon_selected"];
    _lastImageTag = (int)(102030 + (btn.tag - 302010));
    
    
    taxisView.hidden = YES;
    _SortButton.selected = NO;
    pageNum = 1;
    [_myDataArr removeAllObjects];
    
    [self getTestData:btn.tag - 302010 + 1 WithSearch:_searchBar.text withShow:YES];
    
}

#pragma mark------下属客户的下拉
- (void)addViews{
    paixuView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, [UIView getWidth:150.0f], [UIView getHeight:150.0f])];
    paixuView.backgroundColor = [UIColor clearColor];
    paixuView.hidden = YES;
    [self.view addSubview:paixuView];
    
    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, paixuView.width, paixuView.height)];
    bgImage.image = [UIImage imageNamed:@"HY_popup_bg"];
    bgImage.userInteractionEnabled = YES;
    
    [paixuView addSubview:bgImage];
    [self createPaixuView];
}

- (void)createPaixuView{
    CGFloat btnH = (paixuView.height - [UIView getHeight:10] - (_titleArray.count -1) * 1) / _titleArray.count;
    CGFloat btnW = paixuView.width - 20 - 20;
    for (int i = 0; i<_titleArray.count; i++) {
        UIButton  *btn = [[UIButton alloc] initWithFrame:CGRectMake(15, [UIView getHeight:10] + (btnH) * i, btnW, btnH)];
        [btn setTitle:_titleArray[i] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0f];
        btn.backgroundColor = [UIColor clearColor];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        [btn addTarget:self action:@selector(clickOtherSort:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 300200100+ i;
        
        [paixuView addSubview:btn];
        if (i != _titleArray.count - 1) {
            UIView *line = [ViewTool getLineViewWith:CGRectMake(0, btn.maxY, paixuView.width , 1) withBackgroudColor:[UIColor whiteColor]];
            [paixuView addSubview:line];
        }
        
        UIImageView  *imagev = [[UIImageView alloc] initWithFrame:CGRectMake(paixuView.width - 35, btn.y+ 12, 20, 20)];
        imagev.tag = 100200300 + i;
        [paixuView addSubview:imagev];
    }
    
    _lastOtherTag = 300200100;
    //    UIButton *btn = (UIButton *)[taxisView viewWithTag:_lastTag];
    _lastOtherImgTag = 100200300;
    UIImageView  *image = (UIImageView *)[paixuView viewWithTag:_lastOtherImgTag];
    image.image = [UIImage imageNamed:@"HY_popup_icon_selected"];
    
}
- (void)clickToSort111{
    NSLog(@"otherpaixuview");
    if(_paixuButton.selected == NO){
        paixuView.hidden = NO;
    }else{
        paixuView.hidden = YES;
    }
    _paixuButton.selected = !_paixuButton.selected;
}

- (void)clickOtherSort:(UIButton *)btn{
    
    UIImageView *imageV = [paixuView viewWithTag:_lastOtherImgTag];
    imageV.image = nil;
    
    UIImageView *clickImageV = [paixuView viewWithTag:100200300 + (btn.tag - 300200100)];
    clickImageV.image = [UIImage imageNamed:@"HY_popup_icon_selected"];
    _lastOtherImgTag = (int)(100200300 + (btn.tag - 300200100));
    
    
    paixuView.hidden = YES;
    _paixuButton.selected = NO;
    
    otherPageNum = 1;
    [_otherDataArr removeAllObjects];
    [self initOtherData:btn.tag - 300200100 + 1 WithSearch:_otherSearchBar.text WithStaffArray:nil withShow:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.hidesBottomBarWhenPushed = NO;
    self.navigationController.navigationBarHidden = NO;
    
    if (self.isJumpDetail == NO) {//不是跳转到详情界面就刷新
        if (isMyClient) {
            if (taxisView) {
                taxisView.hidden = YES;
                _SortButton.selected = NO;
            }
            _searchBar.text = nil;
            pageNum = 1;
            [_myDataArr removeAllObjects];
            int mydata;
            mydata = _lastImageTag - 102030 + 1;
            [self getTestData:mydata WithSearch:nil withShow:NO];
            [_myClientTableView setContentOffset:CGPointMake(0, 0) animated:YES];
        }else{
            if (paixuView) {
                paixuView.hidden = YES;
                _paixuButton.selected = NO;
            }
            _otherSearchBar.text = nil;
            otherPageNum = 1;
            [_otherDataArr removeAllObjects];
            int mydata;
            mydata = _lastOtherImgTag - 100200300 + 1;
            [self initOtherData:mydata WithSearch:nil WithStaffArray:nil withShow:NO];
            [_otherClientTableView setContentOffset:CGPointMake(0, 0) animated:YES];
            
        }
        
    }else{
        
    }
    self.isJumpDetail = NO;
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    isDismiss = NO;
    [_searchBar resignFirstResponder];
    [_otherSearchBar resignFirstResponder];
}
/**
 *  我的客户
 */
- (void)initMyClientView{
    _myClientView = [[UIView alloc]initWithFrame:CGRectMake(0, view.maxY, KSCreenW, KSCreenH-view.maxY )];
    //_myClientView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_myClientView];
    
    _myClientTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, KSCreenH - view.maxY - TabbarH - 64) style:UITableViewStylePlain];
    _myClientTableView.delegate   = self;
    _myClientTableView.dataSource =self;
    _myClientTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _myClientTableView.backgroundColor = graySectionColor;
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW - 2*STARTX, [UIView getHeight:30])];
    headerView.backgroundColor = graySectionColor;
    //客户总数
    _myBasicLabel = [[UILabel alloc]initWithFrame:CGRectMake(STARTX, [UIView getHeight:5], 200, [UIView getHeight:20])];
    _myBasicLabel.text = [NSString stringWithFormat:@"共有 位客户"];
    _myBasicLabel.textColor = blackFontColor;
    _myBasicLabel.font = [UIFont systemFontOfSize:14.0f];
    [headerView addSubview:_myBasicLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIView getHeight:30] - 1, KSCreenW , 1)];
    lineView.backgroundColor = grayLineColor;
    [headerView addSubview:lineView];
    
    _myClientTableView.tableHeaderView = headerView;
    
    [_myClientView addSubview:_myClientTableView];
    
    _myClientTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadNewData];
    }];
    [_myClientTableView.mj_header beginRefreshing];
    
    // 上拉刷新
    _myClientTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self loadMoreData];
        });
    }];
}
- (void)loadNewData{
    pageNum = 1;
    [_myDataArr removeAllObjects];
    NSInteger mydata;
    mydata = _lastImageTag - 102030 + 1;
    [self getTestData:mydata WithSearch:_searchBar.text withShow:YES];
    
}
- (void)loadMoreData{
    pageNum ++;
    NSInteger mydata;
    mydata = _lastImageTag - 102030 + 1;
    [self getTestData:mydata WithSearch:_searchBar.text withShow:YES];
}
/**
 *  下属客户
 */
- (void)initOtherClientView{
    _otherClientView = [[UIView alloc]initWithFrame:CGRectMake(0, view.maxY, KSCreenW, KSCreenH-view.maxY)];
    _otherClientView.hidden = YES;
    //_otherClientView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_otherClientView];
    
    _otherClientTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, KSCreenH - view.maxY -TabbarH - 64) style:UITableViewStylePlain];
    _otherClientTableView.delegate   = self;
    _otherClientTableView.dataSource =self;
    _otherClientTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _otherClientTableView.backgroundColor = graySectionColor;
    [_otherClientView addSubview:_otherClientTableView];
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW - 2*STARTX, [UIView getHeight:30])];
    headerView.backgroundColor = graySectionColor;
    //客户总数
    _otherBasicLabel = [[UILabel alloc]initWithFrame:CGRectMake(STARTX, [UIView getHeight:5], 200, [UIView getHeight:20])];
    _otherBasicLabel.text = [NSString stringWithFormat:@"共有 位客户"];
    _otherBasicLabel.font = [UIFont systemFontOfSize:14.0f];
    _otherBasicLabel.textColor = blackFontColor;
    [headerView addSubview:_otherBasicLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIView getHeight:30] - 1, KSCreenW, 1)];
    lineView.backgroundColor = grayLineColor;
    [headerView addSubview:lineView];
    
    _otherClientTableView.tableHeaderView = headerView;
    
    _otherClientTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadNewData1];
    }];
    [_otherClientTableView.mj_header beginRefreshing];
    
    // 上拉刷新
    _otherClientTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self loadMoreData1];
        });
    }];
}
- (void)loadNewData1{
    otherPageNum = 1;
    NSInteger mydata;
    mydata = _lastOtherImgTag - 100200300 + 1;
    [_otherDataArr removeAllObjects];
    [self initOtherData:mydata WithSearch:_otherSearchBar.text WithStaffArray:nil withShow:YES];
}
- (void)loadMoreData1{
    otherPageNum++;
    NSInteger mydata;
    mydata = _lastOtherImgTag - 100200300 + 1;
    [self initOtherData:mydata WithSearch:_otherSearchBar.text WithStaffArray:nil withShow:YES];
}
#pragma mark --MyClientView delagte
- (void)segmentView:(TopSegmentView *)segment didScrollIndex:(NSInteger)index{
    if (index == 0) {
        [_searchBar resignFirstResponder];
        [_otherSearchBar resignFirstResponder];
        _paixuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
        [_paixuButton setBackgroundImage:[UIImage imageNamed:@"HY_nav_icon_sort.png"] forState:UIControlStateNormal];
        [_paixuButton addTarget:self action:@selector(clickToSort111) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_paixuButton];
        _paixuButton.selected = NO;
        self.navigationItem.leftBarButtonItem = item;
        
        self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_screen" WithAction:@selector(clickToselectClient:)];
        
        [_topBtnView.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_topBtnView.leftBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
        
        otherPageNum = 1;
        NSInteger mydata;
        mydata = _lastOtherImgTag - 100200300 + 1;
        [_otherDataArr removeAllObjects];
        [self initOtherData:mydata WithSearch:_otherSearchBar.text WithStaffArray:nil withShow:YES];
        
        isMyClient = NO;
        view.hidden = YES;
        otherView.hidden = NO;
        _myClientView.hidden = YES;
        _otherClientView.hidden = NO;
        _paixuButton.hidden = NO;
        _SortButton.hidden = YES;
        
        if (taxisView) {
            taxisView.hidden = YES;
        }
        
        
    }else if(index == 1){
        
        [_searchBar resignFirstResponder];
        [_otherSearchBar resignFirstResponder];
        
        _SortButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
        [_SortButton setBackgroundImage:[UIImage imageNamed:@"HY_nav_icon_sort.png"] forState:UIControlStateNormal];
        [_SortButton addTarget:self action:@selector(clickToSort) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_SortButton];
        _SortButton.selected = NO;
        self.navigationItem.leftBarButtonItem = item;
        
        self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_add" WithAction:@selector(clickToNewClient:)];
        
        [_topBtnView.rightBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
        [_topBtnView.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        isMyClient =YES;
        view.hidden = NO;
        otherView.hidden = YES;
        _myClientView.hidden = NO;
        _otherClientView.hidden = YES;
        _paixuButton.hidden = YES;
        _SortButton.hidden = NO;
        
        if (paixuView) {
            paixuView.hidden = YES;
        }
        
        NSInteger mydata;
        mydata = _lastImageTag - 102030 + 1;
        
        pageNum = 1;
        [_myDataArr removeAllObjects];
        [self getTestData:mydata WithSearch:_searchBar.text withShow:YES];
        
        
    }
}
- (void)segmentView:(TopSegmentView *)segment didSelectIndex:(NSInteger)index withTitle:(NSString *)btnTitlte
{
    if (index == 0) {
        [_searchBar resignFirstResponder];
        [_otherSearchBar resignFirstResponder];
        
        _paixuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
        [_paixuButton setBackgroundImage:[UIImage imageNamed:@"HY_nav_icon_sort.png"] forState:UIControlStateNormal];
        [_paixuButton addTarget:self action:@selector(clickToSort111) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_paixuButton];
        _paixuButton.selected = NO;
        self.navigationItem.leftBarButtonItem = item;
        
        self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_screen" WithAction:@selector(clickToselectClient:)];
        
        [_topBtnView.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_topBtnView.leftBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
        
        otherPageNum = 1;
        NSInteger mydata;
        mydata = _lastOtherImgTag - 100200300 + 1;
        [_otherDataArr removeAllObjects];
        [self initOtherData:mydata WithSearch:_otherSearchBar.text WithStaffArray:nil withShow:YES];
        
        isMyClient = NO;
        view.hidden = YES;
        otherView.hidden = NO;
        _myClientView.hidden = YES;
        _otherClientView.hidden = NO;
        _paixuButton.hidden = NO;
        _SortButton.hidden = YES;
        
        if (taxisView) {
            taxisView.hidden = YES;
        }
        
    }else if(index == 1){
        [_searchBar resignFirstResponder];
        [_otherSearchBar resignFirstResponder];
        
        _SortButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)];
        [_SortButton setBackgroundImage:[UIImage imageNamed:@"HY_nav_icon_sort.png"] forState:UIControlStateNormal];
        [_SortButton addTarget:self action:@selector(clickToSort) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_SortButton];
        _SortButton.selected = NO;
        self.navigationItem.leftBarButtonItem = item;
        
        self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_add" WithAction:@selector(clickToNewClient:)];
        
        [_topBtnView.rightBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
        [_topBtnView.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        isMyClient =YES;
        view.hidden = NO;
        otherView.hidden = YES;
        _myClientView.hidden = NO;
        _otherClientView.hidden = YES;
        _paixuButton.hidden = YES;
        _SortButton.hidden = NO;
        
        if (paixuView) {
            paixuView.hidden = YES;
        }
        
        NSInteger mydata;
        mydata = _lastImageTag - 102030 + 1;
        
        pageNum = 1;
        [_myDataArr removeAllObjects];
        [self getTestData:mydata WithSearch:_searchBar.text withShow:YES];
        
    }
}

#pragma mark
#pragma mark-------- 新建客户
- (void)clickToNewClient:(UIButton *)sender{
    CATransition* transition = [CATransition animation];
    transition.type = kCATransitionMoveIn;//可更改为其他方式
    transition.subtype = kCATransitionFromTop;//可更改为其他方式
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    NewClientViewController * vc  = [[NewClientViewController alloc]init];
    
    [self.navigationController pushViewController:vc animated:NO];
}
#pragma mark
#pragma mark--------选择下属客户
- (void)clickToselectClient:(UIButton *)sender{
    self.isJumpDetail = YES;
    SelectPersonViewController *selectVC = [[SelectPersonViewController alloc] init];
    selectVC.delegate = self;
    selectVC.modalPresentationStyle =  UIModalPresentationPageSheet;
    selectVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    
    [self.navigationController pushViewController:selectVC animated:YES];
}

//SelectStaffViewDelegate
- (void)getSelectedStaff:(NSArray *)array{
    
    NSLog(@"选择的人的个数%lu wef",(unsigned long)array.count);
    if (_staffArray.count != 0 ) {
        [_staffArray removeAllObjects];
        _staffArray = (NSMutableArray *)array;
    }
    NSMutableArray *ids = [NSMutableArray array];
    for (UserModel *user in array) {
        NSString *uid = [NSString stringWithFormat:@"%d",user.uid];
        [ids addObject:uid];
    }
    NSLog(@"%@+++++++llllllllllll",ids);
    
    isDismiss = YES;
    
    int mydata;
    mydata =_lastOtherImgTag - 100200300 + 1;
    otherPageNum = 1;
    [_otherDataArr removeAllObjects];
    [self initOtherData:mydata WithSearch:_otherSearchBar.text WithStaffArray:ids withShow:YES];
    
}

#pragma mark
#pragma mark ------tableView的协议方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _myClientTableView){
        return [MyClientCell cellHeight];
    }else if (tableView == _otherClientTableView){
        return [OtherClientCell cellHeight];
    }
    return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == _myClientTableView){
        return _myDataArr.count;
    }else if (tableView == _otherClientTableView){
        return _otherDataArr.count;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _myClientTableView){
        
        static NSString *identifier =@"identifiercell";
        MyClientCell *cell1 = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell1 == nil) {
            cell1 = [[MyClientCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        if (_myDataArr.count > 0) {
        ClientModel *client = _myDataArr[indexPath.row];
        cell1.companyLabel.text = client.company;
        cell1.addressLabel.text = client.address;
        if (indexPath.row == _myDataArr.count -1) {
            cell1.lineView.frame = CGRectMake(0, [MyClientCell cellHeight] - 1, KSCreenW, 1);
        }else{
            cell1.lineView.frame = CGRectMake(cell1.companyLabel.x, [MyClientCell cellHeight] - 1, KSCreenW, 1);
        }
        if (client.vstatus == 1 ) {//已拜访
            if (client.visittime != nil) {
                NSString *hadVisitTime = client.visittime;
                
                NSDate *date = [NSDate date];
                NSDateFormatter *formate = [[NSDateFormatter alloc] init];
                [formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//HH 大写就是24小时制 小写就是12小时制
                NSString * dateStr = [formate stringFromDate:date];
                
                NSString *nowStr = dateStr;
                NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
                [dateformate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *newDate = [dateformate dateFromString:nowStr];
                NSDate *visitDate = [dateformate dateFromString:hadVisitTime];
                
                NSString *hour = [nowStr substringWithRange:NSMakeRange(11, 2)];
                NSString *min = [nowStr substringWithRange:NSMakeRange(14, 2)];
                NSString *tim = [nowStr substringWithRange:NSMakeRange(17, 2)];
                double all = [hour intValue]* 3600 + [min intValue]* 60 + [tim intValue];
                
                
                double timer1 = [newDate timeIntervalSince1970];
                double timer2 = [visitDate timeIntervalSince1970];
                double cha = timer1 - timer2 -all;
                float days =  (float)cha / (3600.0f * 24);
                
                NSLog(@"%f -------时间差   %@当前时间  %f ++++ ",days,hadVisitTime,cha);
                
                if (days <0) {
                    cell1.statusLabel.text = @"今日已拜访";
                }else if ( days <= 1.0f){
                    cell1.statusLabel.text = @"昨日已拜访";
            
                }else if(days >1.0){
                    int a1 = (int)days;
                    cell1.statusLabel.text = [NSString stringWithFormat:@"%d天前拜访",a1 +1];
                }
            }else{
                cell1.statusLabel.text = @"未拜访";
            }
            
        }else if(client.vstatus == 2){//未拜访
            
            NSString*  sttt = [DataTool changeType:client.ordertime];
            NSString *orderTime = client.ordertime;
            if (![sttt isEqualToString:@""] && [sttt length] != 0) {
                NSDate *newDate = [self getCurrentTime];
                NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
                [dateformate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *orderDate = [dateformate dateFromString:orderTime];
                NSTimeInterval times = [newDate timeIntervalSinceDate:orderDate];
                
                int days = ABS((int)times / (3600 * 24));
                if (days == 0 ) {
                    cell1.statusLabel.text = @"今日未拜访";
                }else if(times < 0 ){
                    cell1.statusLabel.text = [NSString stringWithFormat:@"%d天前未拜访",days];
                }else{
                    cell1.statusLabel.text = [NSString stringWithFormat:@"%d天后拜访",days];
                }
            }else{
                cell1.statusLabel.text = @"未拜访";
            }
        }else{
            cell1.statusLabel.text = @"未拜访";
        }
        cell1.delegate = self;
        }
        return cell1;
    }else if (tableView == _otherClientTableView){
        static NSString *identifier =@"cell";
        OtherClientCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[OtherClientCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_otherDataArr.count > 0) {
        ClientModel *client = _otherDataArr[indexPath.row];
        cell.companyLabel.text = client.company;
        
        cell.addressLabel.text = client.address;
        cell.principalLabel.text = [NSString stringWithFormat:@"负责人>%@",client.cname];
        if (indexPath.row == _otherDataArr.count -1) {
            cell.lineView.frame = CGRectMake(0, [OtherClientCell cellHeight] - 1, KSCreenW, 1);
        }else{
            cell.lineView.frame = CGRectMake(cell.companyLabel.x, [OtherClientCell cellHeight] - 1, KSCreenW, 1);
        }
        if (client.vstatus == 1 ) {//已拜访
            
            if (client.visittime && ![client.visittime isEqualToString:@""]) {
                NSString *hadVisitTime = client.visittime;
                
                NSDate *date = [NSDate date];
                NSDateFormatter *formate = [[NSDateFormatter alloc] init];
                [formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//HH 大写就是24小时制 小写就是12小时制
                NSString * dateStr = [formate stringFromDate:date];
                
                NSString *nowStr = dateStr;
                NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
                [dateformate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *newDate = [dateformate dateFromString:nowStr];
                NSDate *visitDate = [dateformate dateFromString:hadVisitTime];
                
                NSString *hour = [nowStr substringWithRange:NSMakeRange(11, 2)];
                NSString *min = [nowStr substringWithRange:NSMakeRange(14, 2)];
                NSString *tim = [nowStr substringWithRange:NSMakeRange(17, 2)];
                double all = [hour intValue]* 3600 + [min intValue]* 60 + [tim intValue];
                
                
                double timer1 = [newDate timeIntervalSince1970];
                double timer2 = [visitDate timeIntervalSince1970];
                double cha = timer1 - timer2 -all;
                float days =  (float)cha / (3600.0f * 24);
                
//                NSLog(@"%f -------时间差   %@当前时间  %f ++++ ",days,hadVisitTime,cha);
                
                if (days <0) {
                    cell.statusLabel.text = @"今日已拜访";
                }else if ( days <= 1.0f){
                    cell.statusLabel.text = @"昨日已拜访";
                }else if(days >1.0){
                    int a1 = (int)days;
                    cell.statusLabel.text = [NSString stringWithFormat:@"%d天前拜访",a1+1];
                }
            }else{
                cell.statusLabel.text = @"未拜访";
            }
            
        }else if(client.vstatus == 2){//未拜访
            
            NSString*  sttt = [DataTool changeType:client.ordertime];
            
            if (![sttt isEqualToString:@""] && sttt.length !=0 ) {
                NSString *hadVisitTime = client.ordertime;
                NSDate *newDate = [self getCurrentTime];
                NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
                [dateformate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *visitDate = [dateformate dateFromString:hadVisitTime];
                NSTimeInterval times = [newDate timeIntervalSinceDate:visitDate];
                int days = ABS((int)times / (3600 * 24));
                if (days == 0 ) {
                    cell.statusLabel.text = @"今日未拜访";
                }else if(times < 0){
                    cell.statusLabel.text = [NSString stringWithFormat:@"%d天前未拜访",days];
                }else{
                    cell.statusLabel.text = [NSString stringWithFormat:@"%d天后拜访",days];
                }
                
            }else{
                cell.statusLabel.text = @"未拜访";
            }
        }else{
            cell.statusLabel.text = @"未拜访";
        }
            
        }
        return cell;
        
    }
    return nil;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.isJumpDetail = YES;
    
    ClientModel  *client;
    if (tableView == _myClientTableView) {
        if (taxisView) {
            taxisView.hidden = YES;
            _SortButton.selected = NO;
        }
        if (_myDataArr.count > 0) {
            client = _myDataArr[indexPath.row];
            DetailClientViewController *vc = [[DetailClientViewController alloc]init];
            vc.cID = client.clientId;
            vc.model = client;
            vc.titleStr = client.company;
            
            vc.levelArray = _levelArr;
            vc.fromArray = _fromArr;
            vc.statusArray = _statusArr;
            
            NSLog(@"%d   clientID++++++sjjdkksjdjk ",vc.cID);
            [self.navigationController pushViewController:vc animated:YES];
        }
       
    }else{
        if (paixuView) {
            paixuView.hidden = YES;
            _paixuButton.selected = NO;
        }
        if (_otherDataArr.count > 0) {
            client = _otherDataArr[indexPath.row];
            OtherClientVC *vc = [[OtherClientVC alloc]init];
            vc.cID = client.clientId;
            vc.cUID = client.uid;
            vc.titleStr = client.company;
            
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [_searchBar resignFirstResponder];
    [_otherSearchBar resignFirstResponder];
    if (isMyClient) {
        if (taxisView) {
            taxisView.hidden = YES;
            _SortButton.selected = NO;
        }
    }else{
        if (paixuView) {
            paixuView.hidden = YES;
            _paixuButton.selected = NO;
        }
    }
}
- (void)jumpControllerToMap:(NSString *)btnTitle
{
    MapClientViewController *mapClient = [[MapClientViewController alloc] init];
    [self.navigationController pushViewController:mapClient animated:YES];
}
#pragma mark -----获取当前凌晨时间
- (NSDate *)getCurrentTime{
    NSDate *date1 = [NSDate date];
    
//    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"] ;
     NSTimeZone *gmt = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    [calendar setTimeZone:gmt];
    NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:date1];
    components.day+=0;
    components.hour = 0;
    components.minute = 0;
    components.second = 0;
    NSDate *newDate = [calendar dateFromComponents:components];
    return newDate;
}

#pragma mark
#pragma mark -----searchBar协议方法
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
    if (isMyClient == YES) {
        NSInteger mydata;
        mydata = _lastImageTag - 102030 + 1;
        pageNum = 1;
        [_myDataArr removeAllObjects];
        [self getTestData:mydata WithSearch:searchBar.text withShow:YES];
        
    }else{
        NSInteger mydata;
        mydata =  _lastOtherImgTag - 100200300 + 1;
        otherPageNum = 1;
        [_otherDataArr removeAllObjects];
        [self initOtherData:mydata WithSearch:searchBar.text WithStaffArray:nil withShow:YES];
    }
    [_searchBar resignFirstResponder];
    [_otherSearchBar resignFirstResponder];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)eve{
    [_searchBar resignFirstResponder];
    [_otherSearchBar resignFirstResponder];
}

#pragma mark
#pragma mark -----加载数据
- (void)getTestData:(NSInteger)count WithSearch:(NSString *)str withShow:(BOOL)show{
    if (show == YES) {
//        [SVProgressHUD show];
    }
    
    NSNumber *sortNum = [NSNumber numberWithInteger:count];
    NSNumber *sortwayNum = [NSNumber numberWithInt:2];
    if (count == 4 | count == 3) {
        sortwayNum = [NSNumber numberWithInt:1];
    }
    NSNumber *pagesNum = [NSNumber numberWithInt:pageNum];
    NSNumber *rowsNum = [NSNumber numberWithInt:20];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"token":TOKEN,@"uid":@(UID),@"sort":sortNum,@"sortWay":sortwayNum,@"pages":pagesNum,@"rows":rowsNum}];
    if (str != nil && str.length != 0) {
        [dic setObject:str forKey:@"company"];
    }
    NSLog(@"我的客户参数%@",dic);
    [DataTool postWithUrl:MY_CLIENT_URL parameters:dic success:^(id data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//        [SVProgressHUD dismiss];
        
        NSLog(@"我的客户的数据 %@-----",jsonDic);
        NSMutableArray *array = [DataTool changeType:jsonDic[@"customerList"]];
        if (array) {
            _myBasicLabel.text = [NSString stringWithFormat:@"共有%d位客户",[jsonDic[@"customerCount"]intValue]];
        }
        
        for (int i= 0; i<array.count; i++) {
            ClientModel *client = [[ClientModel alloc]init];
            id dd = [DataTool changeType:array[i]];
            [client setValuesForKeysWithDictionary:dd];
            [_myDataArr addObject:client];
            
        }
        [_myClientTableView reloadData];
        
        [_myClientTableView.mj_header endRefreshing];
        if ([jsonDic[@"customerCount"] integerValue] == _myDataArr.count) {
            [_myClientTableView.mj_footer endRefreshingWithNoMoreData];
        }else{
            [_myClientTableView.mj_footer endRefreshing];
        }
        
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
//        [self.view makeToast:error.localizedDescription];
        [_myClientTableView.mj_header endRefreshing];
        [_myClientTableView.mj_footer endRefreshing];
    }];
    
}
//加载其他客户的数据。。。。
- (void)initOtherData:(NSInteger)count WithSearch:(NSString *)str WithStaffArray:(NSArray *)personArr withShow:(BOOL)show{
    if (show == YES) {
//        [SVProgressHUD show];
    }
    
    NSNumber *sortNum = [NSNumber numberWithInteger:count];
    NSNumber *sortwayNum = [NSNumber numberWithInt:2];
    if (count == 4 | count == 3) {
        sortwayNum = [NSNumber numberWithInt:1];
    }
    NSNumber *pagesNum = [NSNumber numberWithInt:otherPageNum];
    NSNumber *rowsNum = [NSNumber numberWithInt:20];
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setDictionary:@{@"token":TOKEN,@"uid":@(UID),@"sort":sortNum,@"sortWay":sortwayNum,@"pages":pagesNum,@"rows":rowsNum}];
    if (personArr && personArr.count != 0) {
        NSString *str111 = [personArr componentsJoinedByString:@","];
        [dic setObject:str111 forKey:@"userid"];
    }
    if (str != nil && str.length != 0) {
        [dic setObject:str forKey:@"company"];
    }
    
    NSLog(@"下属客户参数%@",dic);
    [DataTool postWithUrl:OTHER_CLIENT_URL parameters:dic success:^(id data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//        [SVProgressHUD dismiss];
        NSLog(@"下属客户数据 %@-----",jsonDic);
        NSMutableArray *array = [DataTool changeType:jsonDic[@"customerList"]];
        if (array) {
            _otherBasicLabel.text = [NSString stringWithFormat:@"共有%d位客户",[jsonDic[@"customerCount"]intValue]];
        }
        
        for (int i= 0; i<array.count; i++) {
            ClientModel *client = [[ClientModel alloc]init];
            id dd = [DataTool changeType:array[i]];
            [client setValuesForKeysWithDictionary:dd];
            [_otherDataArr addObject:client];
        }
        
        [_otherClientTableView reloadData];
        [_otherClientTableView.mj_header endRefreshing];
        if ([jsonDic[@"customerCount"] integerValue] == _otherDataArr.count) {
            [_otherClientTableView.mj_footer endRefreshingWithNoMoreData];
        }else{
            [_otherClientTableView.mj_footer endRefreshing];
        }
     
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
//        [self.view makeToast:error.localizedDescription];
        [_otherClientTableView.mj_header endRefreshing];
        [_otherClientTableView.mj_footer endRefreshing];
    }];
}

@end
